<template>
	<view class="container">
		<view  class="personal-info-box">
			<view class="portrait">
				<image :src="portrait" class="portrait-img"></image>
			</view>
			<view  class="content">
				<view class="name-box">
					<text>{{info.name}}</text>
				</view>
				<view class="job-box">
					<text>工号：{{info.number}}</text>
				</view>
				<view class="wechat-box">
					<text>联系电话：{{info.phone}}</text>
				</view>
			</view>
		</view>
		<view class="scan-record-box" >
			<view class="scan-box border-bottom" @click="record">
				<image src="../../../../static/icon/engineer_home/u970.png" class="scan-icon">
				</image>
				<text class="font">
					录入设备
				</text>
			</view>
			<view class="record-box border-bottom" @click="work">
				<image src="../../../../static/icon/engineer_home/u977.png" class="record-icon">
				</image>
				<text class="font">
					工作单记录
				</text>
			</view>
			<view class="logout-box border-bottom" @click="logout">
				<image src="../../../../static/icon/engineer_home/logout.png" class="logout-icon">
				</image>
				<text class="font">
					退出登录
				</text>
			</view>

		</view>

	</view>
</template>

<script>
	import {
		removeToken,
		removeState,
		getStateSync
	} from '@/utils/auth.js'
	import {getEquipmentById} from '@/api/user/index.js'
	export default {
		data() {
			return {
				portrait: '../../../../static/engineer.png',
				info: {
					portrait: '../../../../static/engineer.png',
					name:'',
					number: '',
					job: '工程师',
					phone: ''
				}
			}
		},
		methods: {
			record() {
				// // 允许从相机和相册扫码
				uni.scanCode({
					success: function(re) {
						let id = re.result.split('=')[1]
						getEquipmentById(id).then((res)=>{
							console.log(res)
							if(res.code == 1){
								if(res.result[0].status == 1){
									uni.hideLoading()
									uni.showToast({
										icon: 'none',
										title: '该设备已存在，请勿重复添加设备'
									})
								}else{
									uni.hideLoading()
									console.log("扫除当前设备id为"+id)
									uni.navigateTo({
										 url: '/pages/views/engineer/EnteringInfo/EnteringInfo?id='+id
									});
									
								}
							}
							
						})
					}
				});
				// uni.navigateTo({
				// 	 url: '/pages/views/engineer/EnteringInfo/EnteringInfo?id='+ 1
				// });
			},
			/**
			 * 退出登录
			 */
			logout() {
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定要退出登录吗？',
					success: function(res) {
						if (res.confirm) {
							that.$store.dispatch('user/logout').then(() => {
								uni.reLaunch({
									url: ("/pages/views/Login/Login")
								})
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			work() {
				uni.navigateTo({
					url: "/pages/views/engineer/WorkOrderList/WorkOrderList"
				})
			}
		},
		onShow() {
			/**
			 * 检验当前是否已经登录
			 */
			
			console.log(this.$store.state)
			console.log(this.$store.getters.name)
			let curRoute = this.$mp.page.route;
			this.$intercept.permission(curRoute)
		},
		onLoad() {
			console.log('登陆之后'+getStateSync())
			this.info = this.$store.state.user ? this.$store.state.user: JSON.parse(getStateSync())
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #EFEFF4;
	}

	
	.container {
		height: 100%;
		display: flex;
		flex-direction: column;
		width: 100%;
	}

	/*************************个人信息box-start*********************************/
	.personal-info-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		background-color: #FFFFFF;
		height: 350rpx;
	}

	/* 头像 */
	.portrait {
		width: 37%;
		height: 100%;
		line-height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.portrait-img {
		border-radius: 100px;
		width: 210rpx;
		height: 210rpx;
	}
	/* 个人信息 */
	.content {
		display: flex;
		flex-direction: column;
		justify-content: center;
		width: 62%;
		height: 100%;
	}

	.name-box {
		width: 100%;
		height: 20%;
		font-size: 36rpx;
	}

	.job-box {
		height: 20%;
		font-size: 30rpx;
	}

	.wechat-box {
		font-size: 30rpx;
		height: 20%;
	}


	.login{
		margin-top: 10rpx;
		text-align: center;
		line-height: 70rpx;
		color: #FFFFFF;
		width: 200rpx;
		height: 70rpx;
		border-radius: 10rpx;
		background-color: #1AAD19;
	}
	/* 扫码和工作单记录 */
	.scan-record-box {
		padding: 20rpx;
		margin-top: 40rpx;
		background-color: #FFFFFF;
		display: flex;
		flex-direction: column;
		height: 250rpx;
	}
	.scan-box,
	.record-box,
	.logout-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		font-size: 26rpx;
		font-weight: 400;
		width: 100%;
		height: 33%;
	}

	.scan-box:active {
		background-color: #EFEFF4;
	}

	.record-box:active {
		background-color: #EFEFF4;
	}

	.logout-box:active {
		background-color: #EFEFF4;
	}

	.scan-icon,
	.record-icon,
	.logout-icon {
		width: 7%;
		height: 50rpx;
	}

	.font {
		margin-left: 5rpx;
		height: 100%;
		line-height: 90rpx;
	}

	.record-box {
		width: 100%;
		height: 33%;
	}

	.logout-box {
		width: 100%;
		height: 33%;


	}

	/*************************个人信息box-end*********************************/
</style>
